import { fallbackRequestGet, fallbackRequestPost } from '@/utils/Request'

/**
 * 请求前缀，后面后台添加网关后需要前缀选择微服务
 */
const URL_PREFIX = 'middle-goods/'

/**
 * 当前登陆用户是否对某些评论进行点赞
 * @param {Array<String|Number>} reviewIds 评论id列表
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const currentPraiseFlagByIds = (reviewIds, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'simple_review_praise/currentPraiseFlagByIds', reviewIds, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 对某个商品的某个简单评论进行一次点赞
 * @param {String|Number} reviewId 评论id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} errorCallback 失败回调
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const addPraiseById = (reviewId, successCallback = null, errorCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'simple_review_praise/addPraiseById', { reviewId }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, errorCallback, fullCallback)
}

/**
 * 取消对某个评论的点赞
 * @param {String|Number} reviewId 评论id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} errorCallback 失败回调
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const cancelPraiseById = (reviewId, successCallback = null, errorCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'simple_review_praise/cancelPraiseById', { reviewId }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, errorCallback, fullCallback)
}
